Skip to content

GH-62: Optimize Flight SQL JDBC Statement execution paths#1090

Open
xborder wants to merge 9 commits intoapache:mainfrom
xborder:optimize-queries-3
Open

GH-62: Optimize Flight SQL JDBC Statement execution paths#1090
xborder wants to merge 9 commits intoapache:mainfrom
xborder:optimize-queries-3

Conversation

@xborder
Copy link
Copy Markdown
Contributor

@xborder xborder commented Mar 24, 2026

What Changed

  • This change simplifies the Flight SQL JDBC request flow for Statement.executeQuery/executeUpdate avoiding the PreparedStatement request flow
  • Preserved the current requirement that Statement.execute(String) still flows through PreparedStatement
    • Right now, Arrow Flight does not offer a good solution for this use case. There is no way for the client to disambiguate between a CommandStatementUpdate or CommandStatemenQuery without doing a server call
  • Moved prepared-statement-specific creation and execution concerns into ArrowFlightPreparedStatement
  • Similarly, created ArrowFlightStatement with specific logic to handle Statements
  • Removed statement/prepared-statement construction details and logic from ArrowFlightMetaImpl. ArrowFlightMetaImpl was left it focused on orchestration

Closes #62.

This PR was assisted by AI

xborder and others added 3 commits March 13, 2026 23:54
* reduced number of requests for Statement

* move meta orchestration

* detect prepared statement
@xborder xborder marked this pull request as ready for review March 24, 2026 22:43
@github-actions
Copy link
Copy Markdown

Thank you for opening a pull request!

Please label the PR with one or more of:

  • bug-fix
  • chore
  • dependencies
  • documentation
  • enhancement

Also, add the 'breaking-change' label if appropriate.

See CONTRIBUTING.md for details.

@jbonofre jbonofre added this to the 20.0.0 milestone Apr 13, 2026
.withQuery(query)
.withExistingStatement(this)
.build()
.prepareAndExecute(callback);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a nitpick, but if we run multiple queries with the same statement using execute we will only close one of the handles in the server.

Code for repro:

    try (Connection connection = DriverManager.getConnection(jdbcUrl, properties);
         Statement statement = connection.createStatement()) {

      for (int i = 1; i <= n; i++) {
        String sql = "SELECT " + i;
        log("Executing: " + sql);

        boolean isResultSet = statement.execute(sql);
        if (isResultSet) {
          try (ResultSet rs = statement.getResultSet()) {
            // consume result set
          }
        } else {
          System.out.println("Updated rows: " + statement.getUpdateCount());
        }
      }
    }

A new prepared statement will be created on each query, but only one ClosePreparedStatement is sent to the server. I believe most Flight SQL servers are stateless and this won't be problematic in that scenario, but in case the server is holding some resources associated with the handle(s) of the prepared statement(s) that aren't closed there will be a leak.

Could we send the close after execution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Java][FlightSQL] Arrow Flight SQL JDBC Driver makes ActionCreatePreparedStatementRequest even for Statement.executeQuery() and Statement.exeute().

3 participants